//
//  HotAskTableView.m
//  SHHCPhone
//
//  Created by Sheng long on 14-9-21.
//  Copyright (c) 2014年 sheng long. All rights reserved.
//

#import "HotAskTableView.h"
#import "HotAskView.h"
#import "HotAskTableViewCell.h"
#import "HotAskViewController.h"
#import "HotAskDetailsViewController.h"

@implementation HotAskTableView

@synthesize askView;

#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 102;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return [askView getHeadView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.autoDataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [NSString stringWithFormat:@"cell%d",indexPath.section];
    HotAskTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil){
        cell = [[HotAskTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    NSMutableDictionary *dic = [self.autoDataArray objectAtIndex:indexPath.row];
    [cell showContent:dic cellSize:[tableView rectForRowAtIndexPath:indexPath].size];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSMutableDictionary *dic = [self.autoDataArray objectAtIndex:indexPath.row];
    HotAskDetailsViewController *vc = [[HotAskDetailsViewController alloc] init];
    vc.dataDic = dic;
    [askView.askVc.navigationController pushViewController:vc animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSMutableDictionary *dic = [self.autoDataArray objectAtIndex:indexPath.row];
    if (![dic objectForKey:@"cellheight"]) {
        [HotAskTableViewCell getCellHeight:dic];
    }
    return [[dic objectForKey:@"cellheight"] floatValue];
}

@end
